//////////////////////elaborado por: Susana Taquichiri////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Boa.AIT.AccesoDatos.Entidades;
using Boa.AIT.Negocios;
using Boa.AIT.Negocios.Servicios;
using Didsoft.Mvc.DataModel;
using Didsoft.Mvc.Controller;
using Didsoft.Mvc.DataModel.Lites;

namespace Boa.AIT.Web.Controllers
{
    public class AIT_EquipoITController : BaseController<AIT_EquipoIT>
    {
	    #region interface servicios AIT_EquipoIT

		private IAIT_EquipoITNegociosServicio servicio = null;

		#endregion
		
		
		#region constructor and overridable

        public AIT_EquipoITController()
        {           
		    servicio = new AIT_EquipoITNegocios();
            base.SetDataModelService(servicio);
            base.DropDownListIdProp = "NombreCompleto";
        }

		#endregion

        public ActionResult Equipos()
        {

            return View();
        }

        [HttpPost]
        public JsonResult JSONListaEquipos(string filter = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {
                var searchedItems = servicio.ListarEquipos();

                var items = searchedItems.Skip(jtStartIndex).Take(jtPageSize).ToList();
                return Json(new { Result = "OK", Records = items, TotalRecordCount = searchedItems.Count() });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }

        [HttpPost]
        public JsonResult JSONListaEquiposSinAsignar(string filter = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {
                var searchedItems = servicio.ListarEquiposNoAsignados();

                var items = searchedItems.Skip(jtStartIndex).Take(jtPageSize).ToList();
                return Json(new { Result = "OK", Records = items, TotalRecordCount = searchedItems.Count() });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }


        [HttpPost]
        public JsonResult JSONListaAccesoriosSinAsignar(string filter = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {
                var searchedItems = servicio.ListarAccesoriosNoAsignados();

                var items = searchedItems.Skip(jtStartIndex).Take(jtPageSize).ToList();
                return Json(new { Result = "OK", Records = items, TotalRecordCount = searchedItems.Count() });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }




        public ActionResult Accesorios() {

            return View();
        }


        [HttpPost]
        public JsonResult JSONListaAccesorios(string filter = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {
                var searchedItems = servicio.ListarAccesorios();

                var items = searchedItems.Skip(jtStartIndex).Take(jtPageSize).ToList();
                return Json(new { Result = "OK", Records = items, TotalRecordCount = searchedItems.Count() });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }



		#region	actions

		[HttpGet]
		public override ActionResult Index()
        {
            return RedirectToAction("FilterList");
        }

        public JsonResult EquiposDeLote(int LoteId)
        {
            try
            {
                List<AIT_EquipoIT> accesos = servicio.ListarEquiposDelLote(LoteId);
                return Json(new { Result = "OK", Records = accesos });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }

        }



		#endregion

    }
}

